package com.atguigu.gulimail.order.conf;

import com.atguigu.gulimail.order.entity.OrderEntity;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.HashMap;

@Configuration
public class MyMQConfig {


    @Bean
    public Queue orderDelayQueue(){
        // Queue(String name, boolean durable, boolean exclusive, boolean autoDelete,
        //			@Nullable Map<String, Object> arguments)
        HashMap<String,Object>arguments=new HashMap<String, Object>();
            arguments.put("x-dead-letter-exchange","order-event-exchange"); //声明当前队列绑定的死信交换机
            arguments.put("x-dead-letter-routing-key","order.release.order");//声明当前队列绑定的死信路由。
            arguments.put("x-message-ttl",30000);
        Queue queue = new Queue("order.delay.queue", true, false, false, arguments);
        return queue;
    }

    @Bean
    public Queue orderRelaeaseOrderQueue(){
        return new Queue("order.release.order.queue",true,false,false,null);
    }

    /**
     * 交换机
     * @return
     */
    @Bean
    public Exchange orderEventExchange(){
        return new TopicExchange("order-event-exchange",true,false,null);
    }

    @Bean
    public Binding orderCreateOrder(){
        return new Binding("order.delay.queue",
                Binding.DestinationType.QUEUE,
                "order-event-exchange",
                "order.create.order",
                null);
    }
    @Bean
    public Binding orderReleaseOrder(){
        return new Binding("order.release.order.queue",
                Binding.DestinationType.QUEUE,
                "order-event-exchange",
                "order.release.order",
                null);
    }

    @Bean
    public Binding StockReleaseOrderBinging(){
        /// stock.release.stock.queue

        return new Binding("stock.release.stock.queue",
                Binding.DestinationType.QUEUE,
                "order-event-exchange",
                "order.release.other.#",
                null);
    }


}
